home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
FREENET
/
BRODIE
/
INTERNET
/
!InternetD
/
c
/
daytime
< prev
next >
Wrap
Text File
|
1995-06-07
|
1KB
|
52 lines
#include "inetd.h"
#include "oslib:h.osword"
#include "oslib:h.territory"
#define DAYTIMESIZE 64
#define DAYTIMEFORMAT "%W3 %M3 %DY %24:%MI:%SE %CE%YR"
static char *daytime_prepare(char *timebuff)
{
oswordreadclock_utc_block utc = { oswordreadclock_OP_UTC } ;
char *end;
xoswordreadclock_utc(&utc);
xterritory_convert_date_and_time(-1, &utc.utc, timebuff,
DAYTIMESIZE, DAYTIMEFORMAT, &end);
*end++ = '\r';
*end++ = '\n';
*end = 0;
return timebuff;
}
void daytime_tcp(int s)
{
char timebuff[DAYTIMESIZE];
int t;
struct sockaddr_in address;
int size = sizeof(struct sockaddr_in);
char *date;
t = accept(s, (struct sockaddr *)&address, &size);
if (t == -1) return;
date = daytime_prepare(timebuff);
ioctl(t, FIONBIO, 1);
send(t, date, strlen(date), 0);
kill_socket(&t);
}
void daytime_udp(int s)
{
struct sockaddr_in address;
int size = sizeof(struct sockaddr_in);
char *date;
char timebuff[DAYTIMESIZE];
if (recvfrom(s, timebuff, DAYTIMESIZE, 0,
(struct sockaddr *)&address, &size) == -1) return;
date = daytime_prepare(timebuff);
sendto(s, date, strlen(date), 0, (struct sockaddr *)&address, size);
}